{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "5f89974a3401dee3",
   "metadata": {
    "collapsed": false
   },
   "source": [
    "## expand() 扩张张量"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "initial_id",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2024-03-31T02:35:56.082570Z",
     "start_time": "2024-03-31T02:35:56.077103Z"
    },
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "import torch\n",
    "import numpy as np"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "id": "55c74f76bf7c9e22",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2024-03-31T02:46:08.355024Z",
     "start_time": "2024-03-31T02:46:08.351402Z"
    },
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "torch.Size([3, 1])\n"
     ]
    }
   ],
   "source": [
    "import torch\n",
    "\n",
    "x = torch.tensor([[1], [2], [3]])\n",
    "print(x.shape) "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 23,
   "id": "886e83f7b0fb0cfc",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2024-03-31T02:46:24.095277Z",
     "start_time": "2024-03-31T02:46:24.086789Z"
    },
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "torch.Size([3, 4])\n",
      "tensor([[1, 1, 1, 1],\n",
      "        [2, 2, 2, 2],\n",
      "        [3, 3, 3, 3]])\n"
     ]
    }
   ],
   "source": [
    "y = x.expand( (3, 4))\n",
    "print(y.shape)  # 输出: torch.Size([3, 4])\n",
    "print(y)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "7432b952c9e18a4d",
   "metadata": {
    "collapsed": false
   },
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.12.7"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
